<template>
  <div class="api-doc-container">
    <div class="header">
      <h1>API接口文档</h1>
    </div>
    
    <div class="content">
      <div class="api-sections">
        <div class="api-section">
          <h3>RESTful API 规范</h3>
          <div class="api-content">
            <h4>基础信息</h4>
            <ul>
              <li><strong>Base URL:</strong> https://api.example.com/v1</li>
              <li><strong>认证方式:</strong> Bearer Token</li>
              <li><strong>数据格式:</strong> JSON</li>
              <li><strong>字符编码:</strong> UTF-8</li>
            </ul>
          </div>
        </div>
        
        <div class="api-section">
          <h3>用户管理接口</h3>
          <div class="api-endpoint">
            <div class="endpoint-header">
              <a-tag color="green">GET</a-tag>
              <code>/users</code>
              <span class="endpoint-desc">获取用户列表</span>
            </div>
            <div class="endpoint-details">
              <h5>请求参数</h5>
              <a-table :columns="paramColumns" :data-source="getUsersParams" :pagination="false" size="small" />
              
              <h5>响应示例</h5>
              <pre class="code-block">{
  "code": 200,
  "message": "success",
  "data": {
    "users": [
      {
        "id": 1,
        "name": "张三",
        "email": "zhangsan@example.com"
      }
    ],
    "total": 1
  }
}</pre>
            </div>
          </div>
          
          <div class="api-endpoint">
            <div class="endpoint-header">
              <a-tag color="blue">POST</a-tag>
              <code>/users</code>
              <span class="endpoint-desc">创建用户</span>
            </div>
            <div class="endpoint-details">
              <h5>请求体</h5>
              <pre class="code-block">{
  "name": "李四",
  "email": "lisi@example.com",
  "password": "123456"
}</pre>
              
              <h5>响应示例</h5>
              <pre class="code-block">{
  "code": 201,
  "message": "用户创建成功",
  "data": {
    "id": 2,
    "name": "李四",
    "email": "lisi@example.com"
  }
}</pre>
            </div>
          </div>
        </div>
        
        <div class="api-section">
          <h3>错误码说明</h3>
          <a-table :columns="errorColumns" :data-source="errorCodes" :pagination="false" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const paramColumns = [
  { title: '参数名', dataIndex: 'name', key: 'name' },
  { title: '类型', dataIndex: 'type', key: 'type' },
  { title: '必填', dataIndex: 'required', key: 'required' },
  { title: '说明', dataIndex: 'description', key: 'description' }
]

const getUsersParams = [
  { name: 'page', type: 'number', required: '否', description: '页码，默认为1' },
  { name: 'limit', type: 'number', required: '否', description: '每页数量，默认为10' },
  { name: 'keyword', type: 'string', required: '否', description: '搜索关键词' }
]

const errorColumns = [
  { title: '错误码', dataIndex: 'code', key: 'code' },
  { title: '说明', dataIndex: 'message', key: 'message' }
]

const errorCodes = [
  { code: 200, message: '请求成功' },
  { code: 400, message: '请求参数错误' },
  { code: 401, message: '未授权访问' },
  { code: 403, message: '禁止访问' },
  { code: 404, message: '资源不存在' },
  { code: 500, message: '服务器内部错误' }
]
</script>

<style scoped>
.api-doc-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.header {
  padding: 24px 32px;
  border-bottom: 1px solid #f0f0f0;
}

.header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #262626;
}

.content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

.api-sections {
  max-width: 1000px;
}

.api-section {
  margin-bottom: 32px;
  padding: 24px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid #f0f0f0;
}

.api-section h3 {
  color: #262626;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.api-content ul {
  margin: 0;
  padding-left: 20px;
}

.api-content li {
  color: #595959;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.api-endpoint {
  margin-bottom: 24px;
  padding: 20px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
}

.endpoint-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.endpoint-header code {
  background: #f6f8fa;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 14px;
}

.endpoint-desc {
  color: #595959;
  font-size: 14px;
}

.endpoint-details h5 {
  color: #262626;
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 8px 0;
}

.code-block {
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 16px;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  margin: 8px 0;
}
</style>